package org.example.project3.Controller;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.example.project3.DTO.CategoryDTO;
import org.example.project3.Entity.Category;
import org.example.project3.Result_.Result;
import org.example.project3.Service.CategoryServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bigevent/article/category")
@Slf4j
@Api(tags = "文章分类接口")
public class ArticleCategoryController {
    @Autowired
    CategoryServiceImpl categoryService;

    /**
     * 新增文章分类
     * @param dto
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody CategoryDTO dto){
        log.info("新增分类dto：{}",dto);
        categoryService.add(dto);
        return Result.success();
    }

    /**
     * 查询所有分类
     * @return
     */
    @GetMapping
    public Result getCategory(){
        log.info("查询所有分类");
        List<Category> categoryList = categoryService.getCategory();
        return Result.success(categoryList);
    }

    /**
     * 根据分类id删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public Result deleteByid(String id){
        log.info("删除的分类id:{}",id);
        categoryService.delete(Integer.parseInt(id));
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody CategoryDTO dto){
        log.info("修改的dto:{}",dto);
        categoryService.update(dto);
        return Result.success();
    }
}